	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/template_padrao.xhtml">

	<ui:define name="content">

		<h2>Cadastro de Obras</h2>
		<br />

		<h:form id="form_cad_obra" prependId="false">

			<p:fieldset styleClass="fieldsetPadrao">
				<legend>Dados Principais</legend>

				<table class="formulario">

					<tr>
						<td><h:outputLabel value="Responsável"     title="Gererente responsável" styleClass="ob" /></td>
						<td><h:outputLabel value="Mestre de Obras:" title="Mestre de obras responsável" styleClass="ob" /></td>
						<td><h:outputLabel value="Metros Quadrados" styleClass="ob" /></td>
						<td><h:outputLabel value="Descrição"      title="Decrição da obra." styleClass="ob" /></td>						
					</tr>

					<tr>
						<td><p:selectOneMenu value="#{obraMB.obra.pessoa.id}"
											required="true" 
											label="Responsável">
								<f:selectItems value="#{obraMB.listaResponsaveis}" var="#{resp}"
									itemValue="#{resp.id}" itemLabel="#{resp.nome}" />
							</p:selectOneMenu></td>
							
						<td><p:selectOneMenu value="#{obraMB.obra.mestreObras.id}"
											required="true" 
											label="Mestre de Obras">
								<f:selectItems value="#{obraMB.listaMestreObras}" var="#{resp}"
									itemValue="#{resp.id}" itemLabel="#{resp.nome}" />
							</p:selectOneMenu></td>							
							
						<td><p:inputText value="#{obraMB.obra.qtdMetrosQuadrados}"
										 required="true"/></td>
						
						<td><p:inputText value="#{obraMB.obra.descricao}"
													required="true" 
													label="Descrição" /></td>
													

					</tr>

					<tr>
						<td><h:outputLabel value="Valor Previsto" title="Previsão do valor para a conclusão da obra" styleClass="ob" /></td>
						<td><h:outputLabel value="Data Crítica" title="Indica quando a obra entrará na lista da tela inicial" styleClass="ob" /></td>
						<td><h:outputLabel value="Início" title="Previsão de Início da obra" styleClass="ob" /></td>
						<td><h:outputLabel value="Término" title="Previsão de Término da obra" styleClass="ob" /></td>
						
					</tr>

					<tr>						
						<td><p:inputText value="#{obraMB.obra.valorPrevisto}">
								<f:convertNumber currencyCode="BRL" type="number" />
							</p:inputText></td>
							
						<td><p:calendar	value="#{obraMB.obra.dataCritica.time}"
										pattern="dd/MM/yyyy" 
										locale="pt_BR" 
										label="Data Crtica"	/></td>
							
						<td><p:calendar	value="#{obraMB.obra.dataPrevisaoInicio.time}"
										pattern="dd/MM/yyyy" 
										locale="pt_BR" 
										disabled="#{obraMB.obra.id != 0 and !obraMB.administrator}"/></td>
										
						<td><p:calendar	value="#{obraMB.obra.dataPrevisaoTermino.time}"
										pattern="dd/MM/yyyy"  
										locale="pt_BR" 
										disabled="#{obraMB.obra.id != 0 and !obraMB.administrator}">											
											<p:ajax event="dateSelect"  listener="#{obraMB.atualizarDataTerminoAcabamento()}" update="@form"/>										
										</p:calendar></td>
										
	

					</tr>
				</table>

			</p:fieldset>
			<br />

			<p:fieldset styleClass="fieldsetPadrao">
				<legend>Endereço</legend>

				<table class="formulario">

					<tr>
						<td colspan="2"><h:outputLabel value="Rua"    styleClass="ob"/></td>
						<td colspan="3"><h:outputLabel value="Bairro" styleClass="ob"/></td>
					</tr>

					<tr>
						<td colspan="2"><p:inputText value="#{obraMB.obra.endereco.rua}" 
													 required="true" 
													 label="Rua"/></td>
													 
						<td colspan="3"><p:inputText value="#{obraMB.obra.endereco.bairro}" 
													 size="82" 
													 required="true"
													 label="Bairro"/></td>
					</tr>

					<tr>
						<td><h:outputLabel value="Número"      styleClass="ob" /></td>
						<td><h:outputLabel value="Complemento" styleClass="ob"/></td>
						<td><h:outputLabel value="Cep" 		   styleClass="ob"/></td>
						<td><h:outputLabel value="Cidade" 	   styleClass="ob"/></td>
						<td><h:outputLabel value="Estado"      styleClass="ob"/></td>
					</tr>

					<tr>
						<td><p:inputText value="#{obraMB.obra.endereco.numero}" 
										 required="true"
										 label="Número"/></td>
										 
						<td><p:inputText value="#{obraMB.obra.endereco.complemento}" 
										 required="true"
										 label="Complemento"
										 immediate="false"/></td>
										 
						<td><p:inputMask mask="99999-999"
										 value="#{obraMB.obra.endereco.cep}" 
										 required="true"
										 label="Cep"/></td>
										 
						<td><p:inputText value="#{obraMB.obra.endereco.cidade}"
										 required="true"
										 label="Cidade"/></td>
										 
						<td><p:selectOneMenu value="#{obraMB.obra.endereco.estado}"
											 converter="converterEstado"
											 required="true"
											 label="Estado">											 
								<f:selectItems value="#{obraMB.listaEstados}" var="est"
											   itemLabel="#{est.toString()}" />
							</p:selectOneMenu></td>
					</tr>
				</table>

			</p:fieldset>

			<br />

			<h:panelGroup id="pnl_estagio_obra"> 
				<p:fieldset styleClass="fieldsetPadrao">

					<p:dataTable value="#{obraMB.listaEstagios}" 
								 var="estagio" 
								 styleClass="formulario" >						
										
						<p:column>
							<f:facet name="header">
								<h:outputText value="Estágio" />
							</f:facet>
								<h:outputText value="#{estagio.estagio.toString()}" />					
						</p:column>	
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="Conclusão" title="Porcentagem Conclusão" styleClass="ob"/>
							</f:facet>
								<h:inputText  value="#{estagio.percentualConclusaoEstagio}" 
											  size="1" 
											  required="true" 
											  label="Porcentagem Conclusão"> %
									<f:convertNumber type="number"/>
								</h:inputText>					
						</p:column>								
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="PV" title="Valor Planejado"/>
							</f:facet>
							<h:outputText value="#{estagio.valorPlanejado}" >
								<f:convertNumber currencySymbol="R$" type="currency" />
							</h:outputText>
						</p:column>						
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="AC" title="Custo Real"/>
							</f:facet>
							<h:outputText value="#{estagio.valorTotal}">
								<f:convertNumber currencySymbol="R$" type="currency" />
							</h:outputText>
						</p:column>
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="EV" title="Valor Agregado"/>
							</f:facet>
							<h:outputText value="#{estagio.valorAgregado}">
								<f:convertNumber currencySymbol="R$" type="currency" />
							</h:outputText>
						</p:column>
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="Inicio" styleClass="ob"/>
							</f:facet>
							<p:calendar value="#{estagio.dataInicio.time}"
										required="true"
										navigator="true"
										readonlyInput="true" 
										pattern="dd/MM/yyyy" 
										locale="pt_BR" />					
						</p:column>
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="Termino" styleClass="ob"/>
							</f:facet>
							<p:calendar value="#{estagio.dataTermino.time}" 
										required="true" 
										pattern="dd/MM/yyyy" 
										locale="pt_BR" 
										styleClass="inputDate"
										id="cal_term_estagio"
										navigator="true"
										readonlyInput="true">
										<p:ajax event="dateSelect" listener="#{obraMB.atualizarData(estagio)}" update=":form_cad_obra:pnl_estagio_obra"/>			
										</p:calendar> 					
						</p:column>
						
						
						<p:column>
							<f:facet name="header">
								<h:outputText value="Situação" styleClass="ob"/>
							</f:facet>
							<h:selectBooleanCheckbox value="#{estagio.ativo}" />											
						</p:column>
					
					</p:dataTable>				
					
				</p:fieldset>
			</h:panelGroup>
			<br />
			

			<div id="divButton">
				<p:commandButton action="#{obraMB.salvar()}" 
								value="Salvar"
								id="btSalvar" 
								ajax="false" />
				<p:commandButton action="#{obraMB.cancelar}" 
								value="Cancelar"
								id="btCancelar" 
								ajax="false" 
								immediate="true" />
			</div>

			<br />
		</h:form>


	</ui:define>

</ui:composition>

</html>